package com.java.imauoj.mapper;

import com.java.imauoj.moudel.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProblemMapper {

    @Select("SELECT\n" +
            "\tproblem.problem_id,\n" +
            "\tproblem.problem_type,\n" +
            "\tproblem.title,\n" +
            "\tproblem.description,\n" +
            "\tproblem.hint,\n" +
            "\tproblem.source,\n" +
            "\tproblem.tag,\n" +
            "\tproblem.in_date,\n" +
            "\tproblem.is_defunct,\n" +
            "\tproblem.accepted,\n" +
            "\tproblem.submit,\n" +
            "\tproblem.hard,\n" +
            "\tproblem_select.is_radio,\n" +
            "\tproblem_select.`options`,\n" +
            "\tproblem_prog.input,\n" +
            "\tproblem_prog.output,\n" +
            "\tproblem_prog.sample_input,\n" +
            "\tproblem_prog.sample_output,\n" +
            "\tproblem_prog.time_limit,\n" +
            "\tproblem_prog.memory_limit \n" +
            "FROM\n" +
            "\tproblem_select\n" +
            "\tRIGHT\tJOIN problem ON problem_select.problem_id = problem.problem_id\n" +
            "\tLEFT JOIN problem_prog ON problem_prog.problem_id = problem.problem_id ${sql}")
    List<Problem> getProblemList(String sql,String[] list );







    @Update("update problem set title=#{title},description=#{description},hint=#{hint},source=#{source},tag=#{tag},in_date=#{in_date}," +
            "accepted=#{accepted},submit=#{submit},hard=#{hard} where problem_id=#{problem_id}")
    void updateProblem(Problem problem);

    @Insert("insert into problem(problem_type,title,description,hint,source,tag,in_date,defunct,accepted,submit,hard) " +
            "values(#{problem_type},#{title},#{description}#{hint},#{source},#{tag},#{in_date},#{defunct},#{accepted},#{submit},#{hard})")
    @Options(useGeneratedKeys=true, keyProperty="problem_id", keyColumn="id")
    void addProblem(Problem problem);

    @Delete("delete problem where problem_id=#{problem_id}")
    void deleteProblem(int problem_id);

    @Select("select * from problem where problem_id=#{problem_id}")
    Problem getProblem(int problem_id);

    @Select("select * from problem_select where problem_id=#{problem_id}")
    ProblemSelect getProblemSelect(int problem_id);
    @Select("select * from problem_gap where problem_id=#{problem_id}")
    ProblemGap getProblemGap(int problem_id);
    @Select("select * from problem_prog where problem_id=#{problem_id}")
    ProblemProg getProblemProg(int problem_id);

    @Update("update problem_select set is_radio=#{is_radio},options=#{options},answers=#{answers} where problem_id=#{problem_id}")
    void updateProblemSelect(ProblemSelect select);

    @Update("update problem_gap set is_normal=#{is_normal},keywords=#{keywords},nokeywords=#{nokeywords} where problem_id=#{problem_id}")
    void updateProblemGap(ProblemGap gap);

    @Update("update problem_prog set input=#{input},output=#{output},sample_input=#{sample_input},sample_output=#{sample_output},time_limit=#{time_limit},memory_limit=#{memory_limit} where problem_id=#{problem_id}")
    void updateProblemProg(ProblemProg prog);

    @Insert("insert into problem_select(problem_id,is_radio,options,answers) values(#{problem_id},#{is_radio},#{options},#{answers})")
    void addProblemSelect(ProblemSelect select);

    @Insert("insert into problem_gap(problem,_id,is_normal,keywords,nokeywords) values(#{problem_id},#{is_normal},#{keywords},#{nokeywords})")
    void addProblemGap(ProblemGap gap);

    @Insert("insert into problem_prog(problem_id,input,output,sample_input,sample_output,time_limit,memory_limit) values(#{problem_id},#{input},#{output},#{sample_input},#{sample_output},#{time_limit},#{memory_limit})")
    void addProblemProg(ProblemProg prog);

    @Delete("delete problem_select where problem_id=#{problem_id}")
    void deleteProblemSelect(int problem_id);

    @Delete("delete problem_gap where problem_id=#{problem_id}")
    void deleteProblemGap(int problem_id);

    @Delete("delete problem_prog where problem_id=#{problem_id}")
    void deleteProblemProg(int problem_id);
}
